﻿
using HBase;
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Threading;

namespace hconnect {
    public class Device :ZtTask {
        public Device() : base()//构造函数
        {
        }
        SiemensConnect connect = TaskPool.get<SiemensConnect>();
        public override bool excute() {
            if( connect.initfinsh == 1 ) {
                sendCraneTask();
                byte[] b1 = connect.reader(1 ,1 ,1);
               
                byte[] b = null;
                Random r = new Random();
                b = connect.reader(400 ,5 ,4);
                int data = r.Next(1 ,127);
                String dataStr = data.ToString("X2") + " " + r.Next(1 ,127).ToString("X2") + " " + r.Next(1 ,127).ToString("X2") + " " + r.Next(1 ,127).ToString("X2") + " " + r.Next(1 ,127).ToString("X2") + " " + r.Next(1 ,127).ToString("X2");
                connect.writeByteArr(500 ,0 ,Siemens102Util.StrToArraybyte(dataStr));//int
                console(InfoCode.consle_Test, "db1  addr 0 write" + dataStr);
                b = connect.reader(500 ,1 ,5);
                String val = "";
                foreach( byte by in b ) {
                    val += by.ToString("X2") + " ";
                }
                console(InfoCode.consle_Test, "db1  addr 1 read" + val);
                connect.writeByteArr(500 ,25 ,new byte[] { 230 ,2 ,3 ,44 ,66 });
                b = connect.reader(500 ,25 ,5);
                connect.writeInt(500 ,0 ,int.MaxValue);//int
                b = connect.reader(500 ,0 ,10);
                connect.writeShort(500 ,0 ,( short ) 10);
                b = connect.reader(500 ,0 ,10);
                connect.writeByte(500 ,0 ,( byte ) 10);
                b = connect.reader(500 ,0 ,10);
                connect.writeFloat(500 ,0 ,10.1f);
                b = connect.reader(500 ,0 ,10);
            }
            return true;
        }
        public bool sendCraneTask() {
            List<byte> list = new List<byte>();

            list.AddRange(S7ByteUtil.toS7L2(( ushort ) 222));
            list.AddRange(S7ByteUtil.toS7L4(33));
            byte[] list2 = list.ToArray();
            connect.writeByteArr(540 ,2 ,list.ToArray());
            return true;
        }
    }
}
